package com.chaoyong.higo.adapter;

import org.json.JSONArray;

import com.chaoyong.higo.R;
import com.chaoyong.higo.activity.ModifyOrderActivity;
import com.chaoyong.higo.activity.ToShowOrderActivity;
import com.chaoyong.higo.base.BaseAdapter;
import com.chaoyong.higo.bean.ShowOrderManageBean;
import com.chaoyong.higo.bean.TestNewsetBean;
import com.chaoyong.higo.utils.DataTimeTools;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.utils.ViewHolder;
import com.lidroid.xutils.BitmapUtils;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 晒单管理
 * 
 * @author zk
 *
 */
public class OrderManagerAdp extends BaseAdapter<ShowOrderManageBean.DataEntity.ListEntity> {

	/** 商品图片 */
	private ImageView order_goods_iv;
	/** 商品信息 */
	private TextView order_goods_tv;
	/** 商品价格 */
	private TextView order_goods_price;
	/** 修改 */
	private TextView order_notify;

	public OrderManagerAdp(Context context) {
		super(context);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_order_manager_adp, null);
		}

		order_goods_iv = ViewHolder.get(convertView, R.id.order_goods_iv);
		order_goods_tv = ViewHolder.get(convertView, R.id.order_goods_tv);
		order_goods_price = ViewHolder.get(convertView, R.id.order_goods_price);
		order_notify = ViewHolder.get(convertView, R.id.order_notify);

		// 商品名
		String goods_name = mList.get(position).getGoods_name();
		// 商品价值
		String goods_price = mList.get(position).getGoods_price();
		String uri = mList.get(position).getCover_img().get(0);

		final String id = mList.get(position).getId();
		

		order_goods_tv.setText(goods_name);
		order_goods_price.setText(goods_price);
		BitmapUtils utils = new BitmapUtils(mContext);
		// utils.display(order_goods_iv, Values.BASE_IMAGE_URL + uri);
		utils.display(order_goods_iv, uri);

		order_notify.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				//Toast.makeText(mContext, "商品id:" + id, Toast.LENGTH_SHORT).show();
				Intent intent = new Intent(mContext, ModifyOrderActivity.class);
				intent.putExtra("goods_id", id);
				intent.putExtra("id", mList.get(position).getId());
				intent.putExtra("expect", mList.get(position).getExpect());
				intent.putExtra("img", mList.get(position).getCover_img().get(0));
				intent.putExtra("goods_name", mList.get(position).getGoods_name());
				intent.putExtra("goods_price", mList.get(position).getGoods_price());
				intent.putExtra("share_time", DataTimeTools.time2(mList.get(position).getShare_time()));
				intent.putExtra("share_title", mList.get(position).getShare_title());
				intent.putExtra("share_info", mList.get(position).getShare_info());
				int size = mList.get(position).getFace_img().size();
				if(size != 0){
					JSONArray ja = new JSONArray();
					for (int i = 0; i < size; i++) {
						ja.put(mList.get(position).getFace_img().get(i));
					}
					intent.putExtra("face_img", ja.toString());
				}
				mContext.startActivity(intent);
			}
		});

		return convertView;
	}

}
